Question:
Attempt to read property "data_audit" on array laravel view loop foreach

Problem:

Hello everyone I hope someone can help me I can't understand why I have this error.. what am I doing wrong in the @foreach of blade in the view thanks a lot this is my code..


Back :

$audits = DB::table('esiti_audit')->where('employee', $name)->select(['master_zone', 'subarea', 'microarea', 'data_audit', 'esito'])->orderByDesc('data_audit')->get()->toArray();


$data = [];


foreach ($audits as $audit) {


 $areaKey =  "{$audit->master_zone}|{$audit->subarea}|{$audit->microarea}";


                $data[$areaKey][] = [

                    'esito' => $audit->esito,

                    'data_audit' => $audit->data_audit

                ];

            };

        };


Front


<div class="audit-daily-intestazione">

                                            @if (empty($data))

                                            @else

                                                @foreach ($data as $item => $audits)

                                                <div>

                                                    <span class="audit-daily-text39"><strong

                                                            style="font-size: 13px;">{{ \Carbon\Carbon::parse($audits->data_audit)->format('d/m') }}</strong></span>

                                                </div>

                                                @endforeach

                                            @endif

                                        </div>




Solution:

Try this


<div class="audit-daily-intestazione">

    @if (!empty($data))

        @foreach ($data as $item => $audits)

            <div>

                @foreach ($audits as $audit)

                    <span class="audit-daily-text39">

                    <strong style="font-size: 13px;">

                        {{ \Carbon\Carbon::parse($audit['data_audit'])->format('d/m') }}

                    </strong>

                </span>

                @endforeach

            </div>

        @endforeach

    @endif

</div>


Suggested blogs:

>How to merge cells with HTML, CSS, and PHP?

>How to Migrate your apps to Android 13

>How to Read a csv file with php using cURL

>How to read frame from ffmpeg subprocess in Python?

>How to register a schedule with the controller?

>How to resolve the Composer dependency conflicts (Symfony)?


Ritu Singh

Ritu Singh

Submit
0 Answers